package com.xkdx.guangguang.fragment.user;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;

import com.xkdx.guangguang.module.network.AbsModule;
import com.xkdx.guangguang.module.statics.IConstants;

public class UserUpdateBaseInfoModule extends AbsModule {

	JSONObject values;
	private Context context;
	UserInfo userInfo;
	private UserSharePrefence user_sp;
	JSONArray jsonArray;
	JSONObject jsonObj;
	int index;

	public UserUpdateBaseInfoModule(Context context, int index) {
		this.context = context;
		this.index = index;
	}

	@Override
	public void parseData() throws Exception {

		try {

			jsonArray = (JSONArray) result;
			userInfo = new UserInfo();

			jsonObj = (JSONObject) jsonArray.get(0);

			userInfo = parserUpdateRgist(jsonObj.getJSONObject("Content"),
					index);
		} catch (Exception e) {
			throw e;
		}

	}

	private UserInfo parserUpdateRgist(JSONObject userRigist, int index)
			throws Exception {

		try {
			user_sp = new UserSharePrefence(context, IConstants.SP_USER);
			JSONObject stut = (JSONObject) userRigist.get("Result");
			userInfo.setStatus(stut.getString("Status"));
			userInfo.setMessage(stut.getString("Message"));
			if (index == 1) {

			} else if (index == 2) {

			} else if (index == 3) {

				JSONObject detail = stut.getJSONObject("DetailInfo");
				userInfo.setEmail(detail.getString("Email"));
				userInfo.setEmail_isVerified(detail.getString("IsVerified"));
				user_sp.setUserEmail(detail.getString("Email"));
				user_sp.setUserEmailVerified(detail.getString("IsVerified"));
			} else {
				JSONObject detail = stut.getJSONObject("DetailInfo");
				userInfo.setMobilePhone(detail.getString("MobilePhone"));
				userInfo.setMobilePhone_isVerified(detail
						.getString("IsVerified"));
				user_sp.setUserMobilePhone(detail.getString("MobilePhone"));
				user_sp.setUserMobilePhoneVerified(detail
						.getString("IsVerified"));
			}

		} catch (JSONException e) {
			throw e;
		}
		return userInfo;

	}

	public class UserInfo {
		String status;
		String email;
		String email_isVerified;
		String MobilePhone;
		String MobilePhone_isVerified;
		String Message;

		public String getMessage() {
			return Message;
		}

		public void setMessage(String message) {
			Message = message;
		}

		public String getStatus() {
			return status;
		}

		public void setStatus(String status) {
			this.status = status;
		}

		public String getEmail() {
			return email;
		}

		public void setEmail(String email) {
			this.email = email;
		}

		public String getEmail_isVerified() {
			return email_isVerified;
		}

		public void setEmail_isVerified(String email_isVerified) {
			this.email_isVerified = email_isVerified;
		}

		public String getMobilePhone() {
			return MobilePhone;
		}

		public void setMobilePhone(String mobilePhone) {
			MobilePhone = mobilePhone;
		}

		public String getMobilePhone_isVerified() {
			return MobilePhone_isVerified;
		}

		public void setMobilePhone_isVerified(String mobilePhone_isVerified) {
			MobilePhone_isVerified = mobilePhone_isVerified;
		}

	}

}
